package what.basic.table;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;

import what.basic.basiccomponent.*;
import java.util.*;
import javax.swing.table.*;
public class Jdefaulttablemodel implements ActionListener{
	JTable table=null;
	DefaultTableModel dm=null;
Jdefaulttablemodel(){
	JFrame f=new Jframe().jframe("default table model test",300,300,true);
	Object[][] st={
			{"wangpeng",new Integer(91),new Integer(100)}
			,{"zhuxuelian",new Integer(82),new Integer(69)},
			{"meiting",new Integer(47),new Integer(57)},
	};
	String[] names={"name","yuwen","shuxue"};
	dm=new DefaultTableModel(st,names);
	table=new JTable(dm);
	table.setPreferredScrollableViewportSize(new Dimension(550,30));
	JScrollPane sp=new JScrollPane(table);
	JPanel jp=new JPanel();
	JButton b1=new JButton("add row");
	jp.add(b1);
	jp.add(b1);
	b1.addActionListener(this);
	b1=new JButton("delete row");
	jp.add(b1);
	jp.add(b1);
	b1.addActionListener(this);
	Container cp=f.getContentPane();
	cp.add(jp,BorderLayout.NORTH);
	cp.add(sp,BorderLayout.CENTER);
	f.pack();
}
public static void main(String[] args) {
	new Jdefaulttablemodel();
	}
@Override
public void actionPerformed(ActionEvent e) {
	if(e.getActionCommand().equals("add row"))
		dm.addRow(new Vector());
	if(e.getActionCommand().equals("delete row")){
		int rowcount=dm.getRowCount()-1;
		if(rowcount>=0){
			dm.removeRow(rowcount);
			dm.setRowCount(rowcount);
		}
	}
}

}
